<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">角色管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>系统管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">角色管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">


		<div class="row mbl" >
			<div class="col-lg-8">
				<table style="width: 100%;">
					<tr height="50">
						<td align="right" style="width: 100px;">名称:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="name" name="name" /></td>
						<td align="right" style="width: 100px;">描述:&nbsp;&nbsp;</td>
						<td><input type="text"  class="form-control" id="description" name="description" /></td>
						
						<td align="right" style="width: 100px;"><button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="queryRole()">查询</button></td>
						<td align="right"  style="width: 100px;"><button class="btn btn-primary" onclick="addUpdateUser('0')">新增</button></td>
					</tr>
				</table>
				
			</div>
			<div class="col-lg-6">
				<div class="tb-group-actions">
					<!-- <span >当前已选择<span id="Xuannum">0</span>条记录:</span> 
					<button class="btn btn-sm btn-primary" onclick="delePiLiang()">
						<i class="fa fa-check"></i>&nbsp; 删除多项
					</button>   -->
					
				</div>
			</div>
		</div>

		<table
			class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
			<thead>
				<tr>
					<th width="5%">序号</th>
					<th width="10%">名称</th>
					<th width="10%">描述</th>
					<th width="10%">可操作</th>
				</tr>
			</thead>
			<tbody id="roleList"></tbody>
		</table>
	</div>
	<!--END CONTENT-->
</div>

<?} ?>
<script>
	
	var id;
	var adduid;
	var curr;
	$(function() {
		curr=1
		queryRole();
	});
	function getId() {
		return id;
	}
	function getAdduid() {
		return adduid;
	}
	//添加或者编辑
	function addUpdateUser(lid) {
		id = lid;
		layer.open({
			type : 2,
			area : [ '550px', '350px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : false, //不固定
			title : '角色管理',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['保存 ', '关闭'],
			content : ["knowledge-edit-data-saverole.html",'no'],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.save();
	         },
			cancel : function(index) {
			}
			
		});
	}
	//设置用户角色
	function setUser(suid) {
		adduid = suid;
		layer.open({
			type : 2,
			area : [ '850px', '650px' ],
		    scrollbar: false,
		    shadeClose: true,
			fix : false, //不固定
			title : '用户管理',
			//maxmin : true,  
			skin: 'layui-layer-rim', //加上边框
    	    btn: ['保存 ','关闭'],
			content : ["knowledge-edit-data-queryuser.html",'no'],
			yes: function(index,layer){
	                var iframeWin = parent.window[layer.find('iframe')[0]['name']];
	                 iframeWin.save();
	         },
			cancel : function(index) {
			}
			
		});
	}
	
	function del(id) {
		if (confirm("是否确认删除！！")){
			$.ajax({
				type : "post",
				url : "knowledgeEditDataRoleDetele.do",
				dataType : "json",
				data :{
						"id":id
				},
				beforeSend : function(XMLHttpRequest) {},
				success : function(res) {
					if(res[0].result=='success'){
						queryRole();
					}
					layer.msg(res[0].msg);
				}
			});
			//location.href="knowledgeEditDataRoleDetele.do?id="+id; 
		}
	}
	function queryRole() {
			$.ajax({
			type : "post",
			url : "knowledgeEditDataRoleQuery.do",
			dataType : "json",
			data :{
        		"name":$("#name").val() ,
				"description":$("#description").val()
			},
			beforeSend : function(XMLHttpRequest) {},
			success : function(res) {
				var str = "";
				$("#roleList").html("");
				//alert(JSON.stringify(res));
				for ( var i = 0; i < res.length; i++) {
					str += "<tr>"
							+ "<td>"+(i + 1)+ "</td>"
							+ "<td>"+res[i].name+"</td>"
							+ "<td>"+res[i].description+"</td>"
							+ "<td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"del('"
							+ res[i].id
							+ "')\">"
							+ "删除"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"addUpdateUser('"
							+ res[i].id
							+ "')\">"
							+ "编辑"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"setUser('"
							+ res[i].id
							+ "')\">"
							+ "用户"
							+ "</button></td></tr>";
				}
				$("#roleList").append(str);
			}
		});
	};

	
</script>